import InputManager from "./InputManager";
import TipPanel from "../UI/TipPanel";
import Cell from "../Core/Cell";

const {ccclass, property} = cc._decorator;

@ccclass
export default class AudioManager extends cc.Component {
    public static Instance:AudioManager;

    music_volume:number;
    sound_volume:number;

    @property(cc.AudioSource)
    audio_bgm:cc.AudioSource = null;

    @property(cc.AudioSource)
    audio_disappear:cc.AudioSource = null;

    @property(cc.AudioSource)
    audio_fall:cc.AudioSource = null;

    @property(cc.AudioSource)
    audio_move:cc.AudioSource = null;

    @property(cc.AudioSource)
    audio_explore:cc.AudioSource = null;

    onLoad () {
        AudioManager.Instance = this;
    }

    start () {
        AudioManager.Instance.LoadVolume();
        AudioManager.Instance.SetVolume();

        AudioManager.Instance.audio_bgm.play();
        AudioManager.Instance.audio_bgm.loop = true;
    }

    // Play(audioSource:cc.AudioSource)
    // {
    //     if (audioSource == this.audio_bgm) {
    //         audioSource.volume = AudioManager.Instance.music_volume;
    //     }
    //     else
    //     {
    //         audioSource.volume = AudioManager.Instance.sound_volume;
    //     }

    //     audioSource.play();
    // }

    LoadVolume()
    {
        AudioManager.Instance.music_volume = cc.sys.localStorage.getItem('music_volume');
        if(AudioManager.Instance.music_volume == null)
        {
            AudioManager.Instance.music_volume = 1;
        }

        AudioManager.Instance.sound_volume = cc.sys.localStorage.getItem('sound_volume');
        if(AudioManager.Instance.sound_volume == null)
        {
            AudioManager.Instance.sound_volume = 1;
        }
    }

    SetVolume()
    {
        AudioManager.Instance.audio_bgm.volume = AudioManager.Instance.music_volume;

        AudioManager.Instance.audio_disappear.volume = AudioManager.Instance.sound_volume;
        AudioManager.Instance.audio_fall.volume = AudioManager.Instance.sound_volume;
        AudioManager.Instance.audio_move.volume = AudioManager.Instance.sound_volume;
        AudioManager.Instance.audio_explore.volume = AudioManager.Instance.sound_volume;
    }

}
